package com.baymax.test.scene.demo

import android.Manifest
import android.os.Bundle
import android.provider.MediaStore
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.baymax.test.scene.BaseScene
import com.baymax.test.scene.addButton
import com.baymax.test.scene.media.MediaDAO
import com.baymax.test.scene.newSceneFlexContainer
import com.tbruyelle.rxpermissions2.RxPermissions

class MediaDaoScene : BaseScene() {
    override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): View {
        return p1.newSceneFlexContainer {
            RxPermissions(requireActivity()).request(Manifest.permission.READ_EXTERNAL_STORAGE)
                .subscribe()
            addButton("query images") {
                runCatching {
                    val cursor = MediaDAO.getAllMediaPhotos(requireActivity())
                cursor.moveToFirst()
                val id = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.Media._ID))
                val path =
                    cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA))
                val album =
                    cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME))
                val size =
                    cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.SIZE))
                }

            }
        }
    }
}